package br.ita.doacoes.view.cadastrofamilia;

import java.util.ArrayList;
import java.util.List;

import br.ita.doacoes.domain.cadastrofamilia.Familia;
import br.ita.doacoes.view.cadastrofamilia.refresher.Refreshable;
import br.ita.doacoes.view.cadastrofamilia.refresher.Refresher;

public class FamiliaSingleton implements Refreshable{

	private List<ModelToFilter> models;
	
	private final static FamiliaSingleton instance = new FamiliaSingleton();

	// Private constructor suppresses generation of a (public) default constructor
	private FamiliaSingleton() {
		models =  new ArrayList<ModelToFilter>();
		Refresher.add(this);
	}

	public static FamiliaSingleton getInstance() {
		return instance;
	}
	
	private static Familia familia;

	public static Familia getFamilia() {
		return familia;
	}

	public void setFamilia(Familia familia) {
		this.familia = familia;
	}
	
	public void addModel(ModelToFilter model){
		models.add(model);
	}
	
	public void refresh(){
		for(ModelToFilter model : models){
			model.getModel().filterStartedBy(model.getField(), this.familia.getIdFamilia().toString());
		}
	}
	

}
